import type { PostgreSQLDatabaseConfig } from "@nuxt/content";

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  hooks: {
    "pages:extend"(pages) {
      pages.forEach((page) => {
        if (page.path.startsWith("/admin")) {
          page.meta = page.meta || {};
          page.meta.layout = "admin";
        }
        if (page.path.startsWith("/dev")) {
          page.meta = page.meta || {};
          page.meta.layout = "dev";
        }
      });
    },
  },
  routeRules: {
    "/admin/**": { ssr: false },
    "/dev/**": { ssr: false },
    "/**": { ssr: true }, // 默认 SSR
  },
  compatibilityDate: "2025-07-15",
  runtimeConfig: {
    public: {
      apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL,
    },
  },
  content: {
    database: {
      type: "postgres",
      url: process.env.NUXT_POSTGRES_URL,
    } as PostgreSQLDatabaseConfig,
  },
  devtools: { enabled: true },
  modules: [
    "@nuxt/eslint",
    "@vueuse/nuxt",

    "@unocss/nuxt",
    "@pinia/nuxt",
    "pinia-plugin-persistedstate/nuxt",
    "@element-plus/nuxt",
    "@nuxtjs/color-mode",
    "@nuxt/icon",
    "@nuxt/content",
  ],

  css: ["@unocss/reset/tailwind.css", "~/assets/scss/index.scss"],
  app: {
    // head
    head: {
      link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
    },
  },
  // vueuse
  vueuse: {
    ssrHandlers: true,
  },

  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/assets/scss/element/index.scss" as element;`,
        },
      },
    },
  },

  elementPlus: {
    icon: "ElIcon",
    importStyle: "scss",
    themes: ["dark"],
  },
  icon: {
    serverBundle: {
      collections: ["uil", "ep", "mdi"],
    },
  },
  typescript: {
    typeCheck: true,
  },
});
